package leetcode.method.back_tracking;


import java.util.*;

public class Program17Office {

    public Program17Office() {
    }
    String[]map={" ","*","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    List<String>res=new ArrayList<>();
    public List<String> letterCombinations(String digits) {
        if(digits==null||digits.length()==0){
            return new ArrayList<>();
        }
        dfs(digits,new StringBuilder(),0);
        return res;
    }
    void dfs(String digits,StringBuilder letter,int index){
        if(index==digits.length()){
            res.add(letter.toString());
            return;
        }
        char c=digits.charAt(index);
        int pos=c-'0';
        String mapCur=map[pos];
        for(int i=0;i<mapCur.length();i++){
            letter.append(mapCur.charAt(i));
            dfs(digits,letter,index+1);
            letter.deleteCharAt(letter.length()-1);
        }
    }

    public static void main(String[] args) {

        Program17Office program = new Program17Office();
        String digits = "23";
        System.out.println(program.letterCombinations(digits));
    }
}
